Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.2K
Vistas
Is there a way to delete the response of a slash command [Discord.js]

My code is:

client.ws.on('INTERACTION_CREATE', async interaction => {
        const command = interaction.data.name.toLowerCase();
        const args = interaction.data.options;

        if (command === 'test'){ 
        console.log("Test executed")
        
        client.api.interactions(interaction.id, interaction.token).callback.post({
            data: {
                type: 4,
                data: {
                    content: "Check"
                }
            }
        })
    }
});

I want to delete the answer but I don't really understand how (Very new to this discord.js thing xd)

I saw this post but can't make the answer work

Can anybody please help :(

EDIT: Is it also possible to have a cooldown for a slash command?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

To delete a reply to an interaction (according to Discord Developer Portal) with discord.js v12 use the following:

client.api.webhooks(client.user.id, interaction.token)
    .messages("@original").delete();

Is it also possible to have a cooldown for a slash command?

Yes, it is definitely possible. It should be very similar to cooldowns for non-slash commands. Here you can take a look at this post, very simple cooldown system. Or here you have something more complex.

Here you can have a look at my simple and far from perfect example concerning cooldown system for slash commands:

const cooldowns = new Set();

client.ws.on("INTERACTION_CREATE", (interaction) => {

    const userId = interaction.member.user.id;
    const commandName = interaction.data.name.toLowerCase();
    
    const cooldownId = `${commandName}_${userId}`;
    const cooldownDuration = 60000; // 60 000 ms = 1 minute

    if (cooldowns.has(cooldownId)) {
        // There is a cooldown, notify user and return
        client.api.interactions(interaction.id, interaction.token).callback.post({
            data: {
                type: 4,
                data: {
                    content: "Wait 1 minute before typing this again!",
                    flags: 64, // make reply ephemeral
                }
            }
        });
        return;
    }

    // Create cooldown for next use
    cooldowns.add(cooldownId);
    setTimeout(() => { // Schedule cooldown deletion
        cooldowns.delete(cooldownId);
    }, cooldownDuration);

    // ... Execute the command ...

});
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda